from zz import zz_code, zz_return
import json


def to_list(file_path):
    json_str = zz_code.get_file_content(file_path)
    dd = json.loads(json_str)
    list = []
    for item in dd:
        list.append(PlayerData(item))
    return list


class PlayerData:
    def __init__(self, player_data=None):
        if player_data is None:
            player_data = {}
        self.go = 430  # 走跑速度
        self.height = 143  # 身高
        self.height_big = 250  # 变大身高
        self.big_disable = False  # 禁用变大
        self.ack = ['q', 0.3, 'a']  # 攻击指令
        self.img = "./game/img/player.png"  # 角色图片路径
        if zz_code.dict_exists_key(player_data, 'go'):
            self.go = player_data['go']

        if zz_code.dict_exists_key(player_data, 'height'):
            self.height = player_data['height']

        if zz_code.dict_exists_key(player_data, 'height_big'):
            self.height_big = player_data['height_big']

        if zz_code.dict_exists_key(player_data, 'ack'):
            self.ack = player_data['ack']

        if zz_code.dict_exists_key(player_data, 'big_disable'):
            self.big_disable = player_data['big_disable']

        if zz_code.dict_exists_key(player_data, 'img'):
            self.img = player_data['img']
